var apiHost = wx.getStorageSync("apiHost"); //请求地址
var Appid = wx.getStorageSync('Appid');
var Secret = wx.getStorageSync('Secret');

var AppidFlag = wx.getStorageSync('AppidFlag');

Page({

  /**
   * 页面的初始数据
   */
  data: {
    height:'',
    initLogLists:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var orderNo = options.orderNo;
    var skuId = options.skuId;
    // orderNo = "201809031142228489";
    // skuId = "d682b09d449d497d954b1b1d6bff47fd";
    
    that.setData({
      orderNo: orderNo,
      skuId: skuId
    })
    that.initLogistics(orderNo, skuId)
  },

  /**
   * 初始化物流信息
   */
  initLogistics: function (orderNo, skuId){
    var that = this;
    wx.showLoading({
      title: '加载中',
      icon: 'loading',
    });

    wx.request({
      url: apiHost + "/mobile/orders/express/info", //仅为示例，并非真实的接口地址
      data: {
        orderNo: orderNo,
        skuId: skuId
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: function (res) {
        var code = res.data.code;
        var msg = res.data.msg;
        console.log(res)
        if (code == "10000") {
          var initLogList = res.data.data.expressList
          var initLogLists = that.data.initLogLists
          for (var i = initLogList.length - 1; i >= 0; i--) {
            initLogLists.push(initLogList[i])
          }
          that.setData({
            initLogistics: res.data.data,
            initLogLists: initLogLists
          })
          that.getHeigth();
        } else {
          that.showMsg(msg);
        }
        wx.hideLoading();   //隐藏加载loading
      }
    })
  },

  /***
   * 获取左边的高度
  */
  leftHeight:function(){
    var that = this;
    this.onReady();     //获取左边高度
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 获取高度
   */
  getHeigth :function(){
    var that = this;
    var query3 = wx.createSelectorQuery();
    var logistics_c_lHeight = "";
    var logistics_IHeight = "";
    var logistics_IIHeight = "";

    query3.select('#logistics_c_l').boundingClientRect();
    query3.select('#logistics_I').boundingClientRect();
    query3.select('#logistics_II').boundingClientRect();
    query3.exec(function (res) {
      logistics_c_lHeight = res[0].height;
      logistics_IHeight = res[1].height;
      logistics_IIHeight = res[2].height;
      console.log(res[0])
      that.setData({
        height: logistics_c_lHeight - logistics_IHeight - logistics_IIHeight
      })
    });
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  }
})